import * as RongIMLib from '@rongcloud/imlib-v4'
import Connection from './connection.js'
import CallService from './call.js'
import Chat from './chat.js'
import { IM_RONGYUN_APPKEY } from '@/config'
import { getMyInfo } from '@/core/storage.js'
import { $go2, makeUrl } from '@/core/router.js'
import * as RongIMEmoji from '@rongcloud/emoji'

export default function() {
	const im = RongIMLib.init({ appkey: IM_RONGYUN_APPKEY })
	let Call = CallService(RongIMLib)
	RongIMEmoji.init()
	
	Call.watchCommand(e => {
		let { messageType, senderUserId } = e
		if (messageType === 'InviteMessage') {
			$go2(makeUrl('/pages/main/tabbar/message/call', {
				targetId: senderUserId,
				isSender: 0
			}))
		}
	})

	return {
		Connection: Connection(im),
		Call,
		RongIMEmoji,
		Chat: Chat(im),
		ConversationType: RongIMLib.CONVERSATION_TYPE,
		MessageType: RongIMLib.CALL_MESSAGE_TYPE,
	}
}
